Repository navigation
feat(agents): Instrument RubyLLM chats - #3183
sl0thentr0py wants to merge 1 commit into
Conversation
f1a41f0 to
8734db7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8734db7. Configure here.
|
Hi Neel, RubyLLM creator here. Thanks for building this, it's great to see Sentry tracing RubyLLM natively. One request before this lands: please don't monkey-patch RubyLLM's internals. You don't need the patches anymore. I added what you were patching around to RubyLLM's public API, and it's on main for 2.2:
And in general: if you need a hook RubyLLM doesn't have, open an issue or ping me before patching. I'm happy to add it to the library, and it's usually quick. That way nothing breaks when RubyLLM moves. Smaller notes on this PR, none blocking:
|
8734db7 to
013260a
Compare
PR risk: mediumFor commit Main concerns: data sent to Sentry, public contract, host performance. This label is a hint for reviewers, not an approval. |
013260a to
a64478f
Compare
a64478f to
0fdbccc
Compare
0fdbccc to
7bf4f38
Compare
af0ef83 to
78e88b5
Compare
78e88b5 to
21d1084
Compare
21d1084 to
6e3a396
Compare
6e3a396 to
5d28a19
Compare
5d28a19 to
fdad57b
Compare
fdad57b to
a34c005
Compare
a34c005 to
2641bdb
Compare
Co-Authored-By: OpenAI <noreply@openai.com>
2641bdb to
3bbf335
Compare
| def with_root_transaction(payload) | ||
| transaction = Sentry.start_transaction( | ||
| name: span_description(payload), | ||
| op: OPERATION, | ||
| origin: ORIGIN | ||
| ) | ||
|
|
||
| begin | ||
| Sentry.with_scope do |scope| | ||
| scope.set_span(transaction) | ||
| execute_span(transaction, payload) { yield } | ||
| end | ||
| ensure | ||
| transaction.finish | ||
| end | ||
| end |
There was a problem hiding this comment.
Standalone RubyLLM chats crash when tracing is disabled or another instrumenter is configured
With Sentry initialized but tracing disabled (the default) or a non-Sentry instrumenter configured, standalone RubyLLM chat calls raise instead of reaching the application block, breaking every chat operation in that configuration.
Evidence
with_chat_spancallswith_root_transactionfor an initialized Sentry scope with no current span; it does not guard againstSentry.start_transactionreturningnil.start_transactionreturnsnilwhen tracing is disabled or its instrumenter argument (:sentryby default) does not match the configured instrumenter. Tracing is disabled when no valid traces sample rate or sampler is configured.scope.set_span(transaction)rejectsnil, and theensurethen callstransaction.finish; the RubyLLM application block is never yielded. The tests configure a traces sample rate of1.0, so they do not cover this path.
Also found at 1 additional location
sentry-agents/spec/sentry/agents/ruby_llm/instrumenter_spec.rb:39-71
Identified by Warden · code-review · 7XS-59X
| message.tool_calls.each do |tool_call| | ||
| result << { | ||
| type: "tool_call", | ||
| id: tool_call.id, | ||
| name: tool_call.name, | ||
| arguments: tool_call.arguments | ||
| }.compact | ||
| end |
There was a problem hiding this comment.
parts iterates tool_calls Hash as ToolCall objects
Non-empty message.tool_calls are a Hash of id=>ToolCall, so one-arg each yields [id, tool_call] arrays and .id/.name raise; request/response message attributes are then dropped by the instrumenter rescue.
Evidence
partsdoesmessage.tool_calls.each do |tool_call|then readstool_call.id/name/arguments.- RubyLLM stores
tool_callsas a Hash (default{}); Hash#eachwith one block arg yields[key, value], not the ToolCall. - The same serializer correctly uses
payload[:chat].tools.valuesfor the tools Hash, showing the intended pattern. Instrumenter#set_request_data/#set_response_datacallSerializer.messages/normalize_messageinsiderescue, so a tool-call message dropsgen_ai.input.messages/gen_ai.output.messagesinstead of recording them.- Specs only exercise empty tool_calls, so this path is untested.
Identified by Warden · code-review · W8J-BVU

Summary
Instruments RubyLLM 2.2 chat operations through the configured RubyLLM instrumenter.
gen_ai.chatroot transactions when no Sentry span is active and child spans withSentry.with_child_spanotherwise.usage.ruby_llmevents.Testing
Issues